import java.net.*;
import java.io.*;

public class Peer implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -610166823779640305L;
	/**
	 * 
	 */

	public int numOnGoingTransfers;
	public InetAddress ipAddress;
	public String username;
	public int port;
	public int uptime;

	public Peer(int n, InetAddress ip, String user, int p, int u) {
		numOnGoingTransfers = n;
		ipAddress = ip;
		username = user;
		port = p;
		uptime = u;
	}
	public Peer(InetAddress ip){
		ipAddress = ip;
	}

	public boolean equals(Object theOther) {
		Peer theOtherPeer = (Peer) theOther;
		if (this.ipAddress.equals(theOtherPeer.ipAddress)) {
			return true;
		}
		return false;
	}

	public int hashCode() {
		return this.ipAddress.hashCode();
	}

	public String toString() {
		if ( username != null && username != " " ) {
			return username;
		} else {
			return ipAddress.toString().split("/")[1];
		}
	}
	public InetAddress getIPAddr(){
		return ipAddress;
	}

	public void setNumOnGoingTransfers(int n) {
		numOnGoingTransfers = n;
	}

	public void setUsername(String user) {
		username = user;
	}

	public void setPort(int p) {
		port = p;
	}

	public void setUptime(int u) {
		uptime = u;
	} 
}
